<template>
  <div style="float: left">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="设备编号:" prop="equipmentNum">
        <el-select v-model="ruleForm.equipmentNum" placeholder="请选择设备编号">
          <el-option label="N2001" value="1"></el-option>
          <el-option label="N1001" value="2"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="连接状态:" prop="connectionStatus">
        <el-select
          v-model="ruleForm.connectionStatus"
          placeholder="请选择连接状态"
        >
          <el-option label="在线" value="true"></el-option>
          <el-option label="关闭" value="false"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="灯杆编号:" prop="lightPostNum">
        <el-select v-model="ruleForm.lightPostNum" placeholder="请选择灯杆编号">
          <el-option label="D001" value="D001"></el-option>
          <el-option label="D002" value="D002"></el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="所在区域:" prop="desc">
        <span>自动加载灯杆坐标</span>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >确认</el-button
        >
        <el-button @click="resetForm">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { PostAddLargeScreen } from "@/api/iotInfo/IargeScreen";
export default {
  data() {
    return {
      ruleForm: {
        equipmentNum: "",
        connectionStatus: true,
        lightPostNum: "",
        localArea: "操场",
        openingTime: "",
        closingTime: "",
      },
      rules: {
        equipmentNum: [
          { required: true, message: "请选择设备编号", trigger: "blur" },
        ],
        connectionStatus: [
          { required: true, message: "请选择连接状态", trigger: "blur" },
        ],
        lightPostNum: [
          { required: true, message: "请选择灯杆编号", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      console.log(this.ruleForm);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          PostAddLargeScreen(this.ruleForm).then((res) => {
            if (res.data) {
              this.$message({
                message: "添加成功",
                type: "success",
              });
              this.$router.push("ShowIargeScreen");
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm() {
      this.$router.push("ShowIargeScreen");
    },
  },
};
</script>